<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::LogSubscriber</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveRecord::LogSubscriber 
            
                <span class="parent">&lt; 
                    
                    <a href="../ActiveSupport/LogSubscriber.html">ActiveSupport::LogSubscriber</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activerecord/lib/active_record/log_subscriber_rb.html">activerecord/lib/active_record/log_subscriber.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-i-identity">identity</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-i-logger">logger</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>O</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-i-odd-3F">odd?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-i-render_bind">render_bind</a>,
              </li>
            
              
              <li>
                <a href="LogSubscriber.html#method-c-reset_runtime">reset_runtime</a>,
              </li>
            
              
              <li>
                <a href="LogSubscriber.html#method-c-runtime">runtime</a>,
              </li>
            
              
              <li>
                <a href="LogSubscriber.html#method-c-runtime-3D">runtime=</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="LogSubscriber.html#method-i-sql">sql</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    
      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class="attr-name">IGNORE_PAYLOAD_NAMES</td>
            <td>=</td>
            <td class="attr-value">[&quot;SCHEMA&quot;, &quot;EXPLAIN&quot;]</td>
          </tr>
          
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"></td>
            </tr>
          
        
      </table>
    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>()
            
            <a href="LogSubscriber.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L18" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 18</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>
  <span class="ruby-keyword">super</span>
  <span class="ruby-ivar">@odd_or_even</span> = <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-reset_runtime">
            
              <b>reset_runtime</b>()
            
            <a href="LogSubscriber.html#method-c-reset_runtime" name="method-c-reset_runtime" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-reset_runtime_source')" id="l_method-c-reset_runtime_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L13" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-reset_runtime_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 13</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">reset_runtime</span>
  <span class="ruby-identifier">rt</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">runtime</span> = <span class="ruby-identifier">runtime</span>, <span class="ruby-number">0</span>
  <span class="ruby-identifier">rt</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-runtime">
            
              <b>runtime</b>()
            
            <a href="LogSubscriber.html#method-c-runtime" name="method-c-runtime" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-runtime_source')" id="l_method-c-runtime_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L9" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-runtime_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 9</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">runtime</span>
  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">RuntimeRegistry</span>.<span class="ruby-identifier">sql_runtime</span> <span class="ruby-operator">||=</span> <span class="ruby-number">0</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-runtime-3D">
            
              <b>runtime=</b>(value)
            
            <a href="LogSubscriber.html#method-c-runtime-3D" name="method-c-runtime-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-runtime-3D_source')" id="l_method-c-runtime-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L5" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-runtime-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 5</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">runtime=</span>(<span class="ruby-identifier">value</span>)
  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">RuntimeRegistry</span>.<span class="ruby-identifier">sql_runtime</span> = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-identity">
            
              <b>identity</b>(event)
            
            <a href="LogSubscriber.html#method-i-identity" name="method-i-identity" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-identity_source')" id="l_method-i-identity_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L63" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-identity_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 63</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">identity</span>(<span class="ruby-identifier">event</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug?</span>

  <span class="ruby-identifier">name</span> = <span class="ruby-identifier">color</span>(<span class="ruby-identifier">event</span>.<span class="ruby-identifier">payload</span>[<span class="ruby-value">:name</span>], <span class="ruby-identifier">odd?</span> <span class="ruby-operator">?</span> <span class="ruby-constant">CYAN</span> <span class="ruby-operator">:</span> <span class="ruby-constant">MAGENTA</span>, <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">line</span> = <span class="ruby-identifier">odd?</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>(<span class="ruby-identifier">event</span>.<span class="ruby-identifier">payload</span>[<span class="ruby-value">:line</span>], <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">true</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">event</span>.<span class="ruby-identifier">payload</span>[<span class="ruby-value">:line</span>]

  <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;  #{name}  #{line}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-logger">
            
              <b>logger</b>()
            
            <a href="LogSubscriber.html#method-i-logger" name="method-i-logger" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-logger_source')" id="l_method-i-logger_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L76" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-logger_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 76</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">logger</span>
  <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">logger</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-odd-3F">
            
              <b>odd?</b>()
            
            <a href="LogSubscriber.html#method-i-odd-3F" name="method-i-odd-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-odd-3F_source')" id="l_method-i-odd-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L72" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-odd-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 72</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">odd?</span>
  <span class="ruby-ivar">@odd_or_even</span> = <span class="ruby-operator">!</span><span class="ruby-ivar">@odd_or_even</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-render_bind">
            
              <b>render_bind</b>(column, value)
            
            <a href="LogSubscriber.html#method-i-render_bind" name="method-i-render_bind" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-render_bind_source')" id="l_method-i-render_bind_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L23" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-render_bind_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 23</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">render_bind</span>(<span class="ruby-identifier">column</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">column</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">binary?</span>
      <span class="ruby-identifier">value</span> = <span class="ruby-node">&quot;&lt;#{value.bytesize} bytes of binary data&gt;&quot;</span>
    <span class="ruby-keyword">end</span>

    [<span class="ruby-identifier">column</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>]
  <span class="ruby-keyword">else</span>
    [<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">value</span>]
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-sql">
            
              <b>sql</b>(event)
            
            <a href="LogSubscriber.html#method-i-sql" name="method-i-sql" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-sql_source')" id="l_method-i-sql_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/11c697383e6fea7834ee1a8ba2815ff0da20f0fe/activerecord/lib/active_record/log_subscriber.rb#L35" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-sql_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/log_subscriber.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">sql</span>(<span class="ruby-identifier">event</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">runtime</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">event</span>.<span class="ruby-identifier">duration</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug?</span>

  <span class="ruby-identifier">payload</span> = <span class="ruby-identifier">event</span>.<span class="ruby-identifier">payload</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">IGNORE_PAYLOAD_NAMES</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">payload</span>[<span class="ruby-value">:name</span>])

  <span class="ruby-identifier">name</span>  = <span class="ruby-node">&quot;#{payload[:name]} (#{event.duration.round(1)}ms)&quot;</span>
  <span class="ruby-identifier">sql</span>   = <span class="ruby-identifier">payload</span>[<span class="ruby-value">:sql</span>].<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">' '</span>)
  <span class="ruby-identifier">binds</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-keyword">unless</span> (<span class="ruby-identifier">payload</span>[<span class="ruby-value">:binds</span>] <span class="ruby-operator">||</span> []).<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">binds</span> = <span class="ruby-string">&quot;  &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">payload</span>[<span class="ruby-value">:binds</span>].<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">col</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">render_bind</span>(<span class="ruby-identifier">col</span>, <span class="ruby-identifier">v</span>)
    }.<span class="ruby-identifier">inspect</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">odd?</span>
    <span class="ruby-identifier">name</span> = <span class="ruby-identifier">color</span>(<span class="ruby-identifier">name</span>, <span class="ruby-constant">CYAN</span>, <span class="ruby-keyword">true</span>)
    <span class="ruby-identifier">sql</span>  = <span class="ruby-identifier">color</span>(<span class="ruby-identifier">sql</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">true</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">name</span> = <span class="ruby-identifier">color</span>(<span class="ruby-identifier">name</span>, <span class="ruby-constant">MAGENTA</span>, <span class="ruby-keyword">true</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">debug</span> <span class="ruby-node">&quot;  #{name}  #{sql}#{binds}&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    